<%
/*
Copyright 2010-2011 CumulusCloud
http://cumuluscloud.cc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@page import="java.util.Vector"%>

<%@page import="cumulusCloud.common.HtmlComponents"%>
<%@page import="cumulusCloud.common.ManageUser"%>
<%@page import="cumulusCloud.common.objects.CloudUser"%>

<%@page import="cumulusCloud.common.InformationServer"%>
<%@page import="dyndns.UpdateEngine"%>
<%@page import="dyndns.UpdateServlet"%>
<%@page import="dyndns.DyndnsConfig"%><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<%=HtmlComponents.headBannerCSS(true)%>
<%=HtmlComponents.headApplicationIcon("dyndns", true)%>
<title>Cloud - DynDNS</title>

</head>
<body>
<%=HtmlComponents.bodyTopBanner("DynDNS", true, true)%>

<%
DyndnsConfig dc = UpdateServlet.ue.getDC();
String action = request.getParameter("action");

if ("set".equals(action)) {
	out.println("<h1>Action</h1>");
	
	DyndnsConfig newdc = new DyndnsConfig();
	newdc.enabled = request.getParameter("enabled") != null;
	newdc.username = request.getParameter("username");
	String password = request.getParameter("password");
	if ( (password == null) || (password.isEmpty()))
		password = dc.password;
	newdc.password = password;
	newdc.hostname = request.getParameter("hostname");
	
	if (newdc.hostname.equals(dc.hostname)) {
		newdc.ip = dc.ip;
	}
	
	Vector<String> status = dc.status;
	for (String stat:status) {
		newdc.status.add(stat);
	}
	
	newdc.saveConfig();
	UpdateServlet.ue.setDC(newdc);
	
	out.println("<hr />");
}
%>


<h1>Status</h1>
<form action=".">
<p>
<input type="submit" value="Refresh"/>
</p>
</form>
<%
dc = UpdateServlet.ue.getDC();
Vector<String> status = dc.status;

if (!status.isEmpty()) {
	out.println("<div style='border-style:solid; border-width:1px;'>");
	
	for (String stat:status) {
		out.println(stat + "<br />");
	}
	
	out.println("</div>");
}


%>


<h1>Configuration</h1>
<p>To use this automatic IP updater, you first need an account in <a href="https://www.dyndns.com/account/entrance/">DynDNS</a>. Then, just fill out the following fields with your DynDNS credential.<br />
Your machine hostname will automatically be set to your DynDNS host</p>

<form method="post" action=".">
<p><input name="action" type="hidden" value="set"/>
Enabled: <input name="enabled" type="checkbox" <%= dc.enabled?"CHECKED":"" %>/><br />
Username: <input name="username" type="text" value="<%= (dc.username!=null)?dc.username:"" %>"/><br />
Password: <input name="password" type="password" /><br />
Hostname: <input name="hostname" type="text" value="<%= (dc.hostname!=null)?dc.hostname:"" %>" size="50"/><br />
<input type="submit" value="Save"/>
</p>
</form>

</body>
</html>